<%@ page import="java.util.UUID" %>
<%@ page import="com.lsk.util.UtilUUID" %><%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2018/7/11 0011
  Time: 下午 6:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <script src="/js/layui/form_verify.js"></script>
    <link rel="stylesheet" type="text/css" href="/plug/oss/style.css" />
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right;margin-right: 100px"  href="javascript:location.replace(location.href);"
   title="刷新"><i class="layui-icon" style="line-height:30px">ဂ</i></a>
<form class="layui-form" action="">
    <input type="hidden" name="id" id="id" value="${activityInfo.id}">
    <input type="hidden" name="orgId" id="orgId" value="${orgId}">
    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name"
                  value='${activityInfo.name}' required  lay-verify="required" placeholder="请输入活动名称" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">转发标题</label>
        <div class="layui-input-block">
            <input type="text" name="transmitTitle" id="transmitTitle"
                  value='${activityInfo.transmitTitle}' required  lay-verify="required" placeholder="请输入微信转发标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item"  >
        <label class="layui-form-label">价格</label>
        <div class="layui-input-block">
            <input type="text" name="price" id="price"
                   <c:if test="${sessionScope.userType ==2}">readonly="readonly"</c:if>     value="${activityInfo.price/100}" required  lay-verify="required" placeholder="请输入活动价格" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item"  >
        <label class="layui-form-label">单独购买价格</label>
        <div class="layui-input-block">
            <input type="text" name="alonePrice" id="alonePrice"
                   <c:if test="${sessionScope.userType ==2}">readonly="readonly"</c:if>     value="${activityInfo.alonePrice/100}" required  lay-verify="required" placeholder="单独购买价格" autocomplete="off" class="layui-input">
        </div>
    </div>

    <div class="layui-form-item"  >
        <label class="layui-form-label">最低价</label>
        <div class="layui-input-block">
            <input type="text" name="minPrice" id="minPrice"
                   <c:if test="${sessionScope.userType ==2}">readonly="readonly"</c:if>     value="${activityInfo.minPrice/100}" required  lay-verify="required" placeholder="最低价" autocomplete="off" class="layui-input">
        </div>
    </div>


    <div class="layui-form-item"  >
        <label class="layui-form-label">团人数</label>
        <div class="layui-input-block">
            <input type="text" name="groupNumber" id="groupNumber"
                   <c:if test="${sessionScope.userType ==2}">readonly="readonly"</c:if>     value="${activityInfo.groupNumber}" required  lay-verify="required" placeholder="请输入活动价格" autocomplete="off" class="layui-input">
        </div>
    </div>






    <div class="layui-form-item" >
        <label class="layui-form-label">一级返利</label>
        <div class="layui-input-block">
            <input type="text" name="oneRebate" id="oneRebate"
                   <c:if test="${sessionScope.userType ==2}">readonly="readonly"</c:if>    value="${activityInfo.oneRebate/100}" required  lay-verify="required" placeholder="请输入一级返利金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item" >
        <label class="layui-form-label">二级返利</label>
        <div class="layui-input-block">
            <input type="text" name="twoRebate" id="twoRebate"
                     value="${activityInfo.twoRebate/100}" required  lay-verify="required"
                   <c:if test="${sessionScope.userType ==2}">readonly="readonly"</c:if>      placeholder="请输入二级返利金额" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">服务费</label>
        <div class="layui-input-block">
            <input type="text" name="serviceMoney" id="serviceMoney"
                   <c:if test="${sessionScope.userType ==2}">readonly="readonly"</c:if>       value="${activityInfo.serviceMoney/100}" required  lay-verify="required" placeholder="请输入服务费" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">开始时间</label>
        <div class="layui-input-block">
            <input  name="startTime" id="startTime"
                     class="layui-input" lay-verify="datetime|required"  >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">结束时间</label>
        <div class="layui-input-block">
            <input  name="endTime" id="endTime"
                     class="layui-input" lay-verify="datetime|required"  >
        </div>
    </div>


    <div class="layui-form-item"  <c:if test="${sessionScope.userType==2 || fn:contains(sessionScope.rec,'/marketing/closeQc')!=true }">style="display:none" </c:if> >
        <label class="layui-form-label">立即制作</label>
        <div class="layui-input-block">
            <input type="radio" name="publicityButton"
              checked="checked"   value="0" title="显示">
            <input type="radio" name="publicityButton"
                   <c:if test="${activityInfo.publicityButton==1}">checked="checked" </c:if>
                   value="1" title="不显示">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">动态数据</label>
        <div class="layui-input-block">
            <input type="radio" name="isfloat"
                   checked="checked"
                   value="0" title="显示">
            <input type="radio" name="isfloat"
                   <c:if test="${activityInfo.isfloat==1}">checked="checked" </c:if>
                   value="1" title="不显示">
        </div>
    </div>


<%--        <div class="layui-form-item" <c:if test="${sessionScope.userType==2}">  style="display:none"  </c:if> >
            <label class="layui-form-label">活动类型</label>
            <div class="layui-input-block">
                <input type="radio" name="type"
                       <c:if test="${activityInfo.type==0}">checked="checked" </c:if>
                       value="0" title="支付参与活动">
                <input type="radio" name="type"
                       <c:if test="${activityInfo.type==1}">checked="checked" </c:if>
                       value="1" title="填写信息参与活动">
                <input type="radio" name="type"
                       <c:if test="${activityInfo.type==2}">checked="checked" </c:if>
                       value="2" title="无需操作参与活动">
            </div>
        </div>--%>








    <c:if test="${activityInfo!=null}">
        <div class="layui-form-item" style="display: flex;align-items: center;">
            <c:if test="${sessionScope.userType ==1}">
                <button class="btn layui-btn" id="uploadMusic" style="margin: 0 40px;">上传活动音乐</button>
            </c:if>
            <span class="layui-form-text" id="uploadStatus"></span>
            <audio style="margin-left: 20px;" src="http://resource.dingyuankeji.shop/dingyuan/activity2020/${orgId}/${activityInfo.id}.mp3" controls></audio>
                <%--<div class="layui-input-block">--%>
                <%--<input  name="activityMusic" id="activityMusic"--%>
                <%--class="layui-input" lay-verify="datetime|required"  >--%>
                <%--</div>--%>
        </div>
    </c:if>


    <div class="layui-form-item">
        <div class="layui-input-block" style="margin-left: 55%">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <c:if test="${activityInfo!=null}">
                <button class="layui-btn layui-btn-normal" type="button" onclick="QRshow()"
                style="margin-left: 5rem">活动二维码</button>
            </c:if>
        </div>
    </div>
    <c:if test="${sessionScope.userType ==1}">
    <div id="container" style="margin-left: 40px;">
        <a id="getfiles" href="javascript:void(0);" class='btn'>选择图片</a>
        <a id="postfiles" href="javascript:void(0);" class='btn'>开始上传</a>
    </div>
    </c:if>
</form>



<script>
    layui.use(['form', 'layedit', 'laydate'], function(){
        var form = layui.form;
        var laydate=layui.laydate;

        laydate.render({
            elem: '#startTime',
            format:'yyyy-MM-dd HH:mm:ss'
            <c:if test="${activityInfo!=null}">
                ,value: '<fmt:formatDate value="${activityInfo.startTime}" pattern="yyyy-MM-dd HH:mm:ss"/>'
            </c:if>
            ,type: 'datetime'
        });
        laydate.render({
            elem: '#endTime',
            format:'yyyy-MM-dd HH:mm:ss'
            <c:if test="${activityInfo!=null}">
            ,value: '<fmt:formatDate value="${activityInfo.endTime}" pattern="yyyy-MM-dd HH:mm:ss"/>'
            </c:if>
            ,type: 'datetime'
        });
        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));
            console.log(JSON.stringify(data.field));
            $.ajax({
                url:'/group/saveGroupActivity',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    id:data.field.id,
                    name:data.field.name,
                    transmitTitle:data.field.transmitTitle,
                    price:data.field.price,
                    oneRebate:data.field.oneRebate,
                    twoRebate:data.field.twoRebate,
                    startTime:data.field.startTime,
                    endTime:data.field.endTime,
                    serviceMoney:data.field.serviceMoney,
                    orgId:data.field.orgId,
                    isfloat:data.field.isfloat,
                    groupNumber:data.field.groupNumber,
                    publicityButton:data.field.publicityButton,
                    alonePrice:data.field.alonePrice,
                    minPrice:data.field.minPrice
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(data){
                    console.log(data);
                    if (data.code=='000000'){
                        layer.msg(data.msg,{time:1000,icon: 6},function () {
                            // 获得frame索引
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            if(''=='${activityInfo.id}' || '${activityInfo.id}'=='null'){
                                parent.layer.close(index);
                            }else {
                                window.location.reload();
                            }


                        });
                    }else {
                        layer.msg(data.msg,{time:1000,icon: 5});
                    }
                    //console.log(data)
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            })

            return false;
        });

    });

    $(function () {
        $.cookie("groupImgStr",null);
        $.cookie("delImgStr",null);
    });
</script>








<script>

</script>
<h2 style="padding:20px 40px;">选择的文件列表</h2>
<div id="ossfile"></div>
<div class="cardFrontImg" id="cardFrontImg">
    <c:forEach items="${imgPathList}" var="img">
        <div class="imgBox">
            <img src="${img.path}" />
            <input class="layui-input" placeholder="图片序号，请填写数字" value="${img.number}" id="${img.id}" ><br>

            <button class="layui-btn " onclick="imgSerial('${img.id}')"   >保存序号</button>
            <button class="layui-btn layui-btn-danger " onclick="delOr(this,'${img.path}')" style="margin-left: 8rem"  >删除</button>
        </div>
    </c:forEach>
</div>
<script>
    function delOr(t,path) {

        $.ajax({
            url:'/group/delGroupImgs',
            type:'POST', //GET
            async:true,    //或false,是否异步
            data:{
                id:path,
                orgId:$("#orgId").val()
            },
            timeout:5000,    //超时时间
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            beforeSend:function(xhr){
                /*console.log(xhr)
                 console.log('发送前')*/
            },
            success:function(data){
                console.log(data);
                if (data.code='000000'){
                    $(t).parents('.imgBox').remove();
                }else {
                    layer.msg("删除失败");
                }
            },
            error:function(xhr,textStatus){
                console.log('错误')
                console.log(xhr)
                console.log(textStatus)
            },
            complete:function(){
                //console.log('结束')
            }
        });

    };

    function imgSerial(id) {
        var tempId="#"+id;
        var number=$(tempId).val();
        var isN=isNumber(number);
        if (isN){
            $.ajax({
                url:'/group/groupImgSerial',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:{
                    id:id,
                    number:number
                },
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(data){
                    console.log(data);
                    if (data.code!='000000'){
                        layer.msg(data.msg,{time:3000,icon: 5});
                    }else {
                        layer.msg(data.msg,{time:500,icon: 6});
                    }
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });
        }else {
            layer.msg("请填写从0开始的数字");
        }

    }



</script>

<script>
    function QRshow() {
        layer.open({
            title:'请使用微信扫描二维码',
            offset: '50px',
            type: 2,
            content: '/group/groupQRshow?activityId=${activityInfo.id}&orgId=${orgId}',
            area: ['30%', '70%'],
            shadeClose:true
        });
    }
</script>

<pre id="console"></pre>
</body>
<script type="text/javascript" src="/plug/oss/cryptobase.js"></script>
<script type="text/javascript" src="/plug/oss/lib/crypto1/hmac/hmac.js"></script>
<script type="text/javascript" src="/plug/oss/lib/crypto1/sha1/sha1.js"></script>
<script type="text/javascript" src="/plug/oss/lib/base64.js"></script>
<script type="text/javascript" src="/plug/oss/lib/plupload-2.1.2/js/plupload.full.min.js"></script>
<script type="text/javascript" src="/plug/oss/groupUpload.js?version=<%=UtilUUID.getUUID()%>"></script>
<script type="text/javascript" src="/plug/oss/groupUploadMp3.js?version=<%=UtilUUID.getUUID()%>"></script>
</html>
